/**
 * 类
 */

// 用来描述一类具体对象的抽象成员
// ts增强了class的相关语法

export {}

class Person {
  public name: string // = 'init name' // 默认修饰符
  private age: number
  protected readonly gender: boolean // readonly需要写在其他修饰符后面

  constructor (name: string, age: number) {
    this.name = name
    this.age = age
    this.gender = true
  }

  sayHi (msg: string): void {
    console.log(`Hi，${this.name}`)
  }
}

class Coder extends Person {
  private constructor (name: string, age: number) {
    super(name, age)
    console.log(this.gender)
  }

  static of (name: string, age: number) {
    return new Coder(name, age)
  }
}

const tom = new Person('tom', 18)
// tom.age 报错 private修饰的属性只允许在类内部使用
// tom.gender 报错 protected修饰的属性只允许在类或者其子类内部使用

// const jerry = new Coder('jerry', 18)
// private修饰的constructor的类，不允许在类外部被实例化或继承
// protected修饰的constructor的类，不允许在类外部被实例化但允许被继承
const jerry = Coder.of('jerry', 18)
